home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / ColorSync 2.5.1 SDK / Sample Code / CSDemo 2.5 / CSDemoSources / winAbout.c < prev    next >
Encoding:
Text File  |  1998-09-09  |  8.8 KB  |  275 lines  |  [TEXT/CWIE]

  1. // An about box window
  2. //
  3. // David Hayward 
  4. // Developer Technical Support
  5. // AppleLink: DEVSUPPORT
  6. //
  7. // Copyrite 1995, Apple Computer,Inc
  8. //
  9. // This file contains the handlers procs for an about box window.
  10. // 
  11. // 12/13/94    david    first cut
  12.  
  13.  
  14. #include <Types.h>
  15. #include <Files.h>
  16. #include <QDOffScreen.h>
  17. #include <Resources.h>
  18. #include <TextEdit.h>
  19.  
  20. #include "appGlobals.h"
  21. #include "appMain.h"
  22. #include "appMenus.h"
  23.  
  24. #include "win.h"
  25. #include "winTables.h"
  26. #include "winAbout.h"
  27.  
  28. #include "resourceUtils.h"
  29.  
  30.  
  31. /**\
  32. |**| ==============================================================================
  33. |**| PRIVATE DEFINES
  34. |**| ==============================================================================
  35. \**/
  36. #define rAboutBoxStringID    2000            // 'STR ' resource id
  37. #define rAboutDocWindID        2000            // 'WIND' resource id
  38.  
  39.  
  40. /**\
  41. |**| ==============================================================================
  42. |**| PRIVATE FUNCTION PROTOTYPES
  43. |**| ==============================================================================
  44. \**/
  45. OSErr        DoCreateAboutWindow        ( winHandle win ) ;
  46.  
  47.  
  48. /**\
  49. |**| ==============================================================================
  50. |**| PUBLIC FUNCTIONS
  51. |**| ==============================================================================
  52. \**/
  53.  
  54.  
  55. /*------------------------------------------------------------------------------*\
  56.     winUpdateAbout
  57.  *------------------------------------------------------------------------------*
  58.         This is a UpdateProcPtr for the About window.  
  59.         It handles all drawing into the window.
  60.         For the About window, this means that this routine is responible for
  61.         drawing the text into the About box.
  62.         This ProcPtr is envoked by CallWinUpdateProc() which is called by:
  63.             DoUpdateEvent() which dispaches update events.
  64. \*------------------------------------------------------------------------------*/
  65. void    winUpdateAbout ( winHandle win, EventRecord *e )
  66. {
  67.     long            length ;
  68.     Rect            aboutRect ;
  69.     Handle            aboutText ;
  70.     WindowRef        window = (WindowRef)e->message;
  71.     GrafPtr            savedPort ;
  72.     
  73.     GetPort( &savedPort ) ;    
  74.     SetPort( (GrafPtr)window ) ;
  75.  
  76.     BeginUpdate( window ) ;
  77.  
  78.     aboutRect = GetRect( rAboutBoxStringID ) ;
  79.  
  80.     aboutText = GetResource( 'TEXT', rAboutBoxStringID ) ;
  81.     HLock( aboutText ) ;
  82.     length = GetHandleSize( aboutText ) ;
  83.     TETextBox( *aboutText, length, &aboutRect, teCenter) ;
  84.     HUnlock( aboutText ) ;
  85.     ReleaseResource( aboutText ) ;
  86.     
  87.     // signal that we finished drawing
  88.     EndUpdate( window ) ;
  89.     SetPort( savedPort ) ;
  90. }
  91.  
  92.  
  93. /*------------------------------------------------------------------------------*\
  94.     winCloseAbout
  95.  *------------------------------------------------------------------------------*
  96.         This is a CloseProcPtr for the About window.
  97.         All this does is call DisposeWinHandle()
  98.         This ProcPtr is envoked by CallWinCloseProc() which is called by:
  99.             app_aePDOC_handler() which handles PDOC AppleEvents,  
  100.             DoMouseDownEvent() which dispached click events (e.g. close box), and
  101.             MenuProcPtrs which are called whenever menu events occur.
  102. \*------------------------------------------------------------------------------*/
  103. void    winCloseAbout ( winHandle win ) 
  104. {
  105.     DisposeWinHandle( win ) ;
  106. }
  107.  
  108.  
  109. /*------------------------------------------------------------------------------*\
  110.     winMenuAbout
  111.  *------------------------------------------------------------------------------*
  112.         This is a MenuProcPtr for the About window.
  113.         This routine dispatches any menu commands that the window can handle
  114.         to the appropriate function.
  115.         For the About window, the only need menu command is File:Close 
  116.         This ProcPtr is envoked by CallWinMenuProc() which is called by:
  117.             HandleMenuCommand() which dispatches all menu events.
  118. \*------------------------------------------------------------------------------*/
  119. void winMenuAbout ( winHandle win, long menuResult, Boolean *didit )
  120. {
  121.     short            menuID;
  122.     short            menuItem;
  123.     winHandle        frontWin;
  124.     
  125.     frontWin = GetFrontWindowWinHandle() ;
  126.     
  127.     if ( win == frontWin )
  128.     {
  129.         *didit = true ;
  130.         menuID   = HiWrd(menuResult) ;
  131.         menuItem = LoWrd(menuResult) ;
  132.         switch ( menuID )
  133.         {
  134.             default :
  135.                 *didit = false ;
  136.                 break ;
  137.         }
  138.         HiliteMenu(0) ;        // Unhighlight whatever MenuSelect or MenuKey hilited
  139.     }
  140. }
  141.  
  142.  
  143.  
  144. /*------------------------------------------------------------------------------*\
  145.     winUpdateMenusAbout
  146.  *------------------------------------------------------------------------------*
  147.         This is a UpdateMenusProcPtr for the About window.
  148.         This routine enables any menu commands that the window can handle.
  149.         For the About window, the only need menu command is File:Close 
  150.         This ProcPtr is envoked by CallWinUpdateMenusProc() which is called by:
  151.             DoAppAdjustMenus() which enables menu commands.
  152. \*------------------------------------------------------------------------------*/
  153. void winUpdateMenusAbout ( winHandle win ) 
  154. {
  155.     MenuHandle        theMenu ;
  156.     winHandle        frontWin;
  157.     
  158.     frontWin = GetFrontWindowWinHandle() ;
  159.     
  160.     if ( win == frontWin )
  161.     {
  162.         // do the file menu
  163.         theMenu = GetMenuHandle ( mFile ) ;
  164.     
  165.             EnableItem ( theMenu, kWholeMenu ) ;
  166.             EnableItem ( theMenu, iClose ) ;
  167.     }
  168. }
  169.  
  170.  
  171. /*------------------------------------------------------------------------------*\
  172.     winAllocAbout
  173.  *------------------------------------------------------------------------------*
  174.         This is a winAllocAbout for the About window.
  175.         This routine is responsible for filling in all the needed fields of the
  176.         winHandle structure. This routine shouldn't be called directly.
  177.         Instead, the code which needs to create a document of this type should
  178.         call NewWinHandle(win,winAllocAbout) to envoke this function.
  179.         This ProcPtr is envoked by NewWinHandle() which is called by:
  180.             DoAboutBoxCommand() which handles the Apple:About menu command.
  181. \*------------------------------------------------------------------------------*/
  182. OSErr winAllocAbout ( winHandle win )
  183. {
  184.     OSErr            err = noErr ;
  185.     
  186.     // set the window type
  187.     SetWinType( win, kAboutDocType ) ;
  188.     
  189.     //  stuff winHandle fields
  190.     SetWinUpdateProc        ( win,      (UpdateProcPtr) winUpdateAbout ) ;
  191.     SetWinMenuProc            ( win,        (MenuProcPtr) winMenuAbout ) ;
  192.     SetWinUpdateMenusProc    ( win, (UpdateMenusProcPtr) winUpdateMenusAbout ) ;
  193.     SetWinNewProc            ( win,         (NewProcPtr) winNewAbout ) ;
  194.     SetWinCloseProc            ( win,       (CloseProcPtr) winCloseAbout ) ;
  195.     
  196.     return err ;    
  197. }
  198.  
  199.  
  200. /*------------------------------------------------------------------------------*\
  201.     winNewAbout
  202.  *------------------------------------------------------------------------------*
  203.         This is a NewProcPtr for the About window.
  204.         This routine is responsible for building a new About window after all the
  205.         needed fields of the winHandle structure have been filled in by winAllocAbout.
  206.         If an About window is already open, then this routine will bring it
  207.         to the front instead of opening a second window.
  208.         This routine shouldn't be called directly.  Instead, the code which needs
  209.         to create a document of this type should call NewWinHandle(win,winAllocAbout),
  210.         and then CallWinNewProc(win) to envoke this function.
  211.         This ProcPtr is envoked by CallWinNewProc() which is called by:
  212.             DoAboutBoxCommand() which handles the Apple:About menu command.
  213. \*------------------------------------------------------------------------------*/
  214. OSErr winNewAbout ( winHandle win )
  215. {
  216.     OSErr            err = noErr ;
  217.     winHandle        existingDoc ;
  218.     
  219.     // see if we are already open
  220.     
  221.      if ( FindWinHandle( nil, kAboutDocType, nil, 1, 1, &existingDoc ) == 1 )
  222.     {
  223.         // bring it to the front
  224.         SelectWindow( GetWinWindow(existingDoc) ) ;        
  225.         return kWasAlreadyOpen ;
  226.     }
  227.     
  228.     err = DoCreateAboutWindow( win ) ;
  229.     if ( err ) return err ;
  230.     
  231.     return err ;    
  232. }
  233.  
  234.  
  235. /**\
  236. |**| ==============================================================================
  237. |**| PRIVATE FUNCTIONS
  238. |**| ==============================================================================
  239. \**/
  240.  
  241.  
  242. /*------------------------------------------------------------------------------*\
  243.     DoCreateAboutWindow
  244.  *------------------------------------------------------------------------------*
  245.         This routine actually creates the WindowRef for a winHandle.
  246.         After creating the window, it:
  247.             reference the window and the DocumentRecord to each other,
  248.             makes the window the current port,
  249.             makes it visible .
  250.         This routine is called by:
  251.             winOpenAbout() which fills in the winHandle structure
  252. \*------------------------------------------------------------------------------*/
  253. static OSErr DoCreateAboutWindow ( winHandle win )
  254. {
  255.  
  256.     OSErr        err = noErr ;
  257.     WindowRef    window ;
  258.     
  259.     window = GetNewCWindow(rAboutDocWindID, nil, (WindowRef)-1 ) ;
  260.     
  261.     SetWinWindow( win, window ) ;            // save a reference to the window in the winRecord
  262.     SetWindowWinHandle( window, win ) ;        // save a reference to the winRecord in the window
  263.  
  264.     SetGWorld( (CGrafPtr)GetWinWindow(win), nil ) ;    // set the window to be the current port
  265.  
  266.     SetWinRect( win, ((CGrafPtr)window)->portRect ) ;
  267.  
  268.     // make sure it is visible
  269.     ShowWindow( window ) ;
  270.  
  271.     return err ;
  272. }
  273.  
  274.  
  275.